﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RegistrationController;

namespace HPMDesktop.Patient
{
    public partial class frmAddConsultantVisit : Form
    {
        private Form _objParentForm; 
        private string _parentClass;
        private string _patientName;
        private string _CRNumber;
        private Hashtable _consultantInfo;

        public frmAddConsultantVisit(Form objParentForm, 
                                     string parentClass,
                                     string patientName,
                                     string CRNumber)
        {
            InitializeComponent();
            _objParentForm = objParentForm;
            _parentClass = parentClass;
            _patientName = patientName;
            _CRNumber = CRNumber;
        }

        private void frmAddConsultantVisit_Load(object sender, EventArgs e)
        {
            txtpname.Text = _patientName;
            txtCRNum.Text = _CRNumber;

            /* Load consultants from db */
            ConsultantInfo_DataLoader objCIDataLoader = new ConsultantInfo_DataLoader();

            _consultantInfo = objCIDataLoader.Get_ConsultantFees_Data();

            foreach (String consultantName in _consultantInfo.Keys)
            {
                cmbConsultant.Items.Add(consultantName);
            }

            objCIDataLoader.Dispose();
        }

        private void cmdCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void cmdOK_Click(object sender, EventArgs e)
        {
            if (cmbConsultant.Text == "")
            {
                MessageBox.Show("Please select a consultant.");
            }
            else
            {
                PatientConsultantVisit_Mapper objMapper = new PatientConsultantVisit_Mapper();
                if (objMapper.add_consultant_visit(_CRNumber, cmbConsultant.Text))
                {
                    if (_parentClass.Equals("frmPatientDetails"))
                    {
                        ((frmPatientDetails)_objParentForm).updateConsultantVisitsView();
                        this.Close();
                    }
                }
                else
                {
                    MessageBox.Show("Error in adding consultant's visit. Try again later.");
                }
            }
        }
    }
}
